# coding=utf-8
import json
import sys
import ibm_db_dbi

reload(sys)
sys.setdefaultencoding('utf-8')

uid = "auth11"
pwd = "password"
database = "UACSDB"
hostname = "127.0.0.1"
dsn = "DRIVER = {IBM DB2 ODBC DRIVER}; DATABASE="+ database + ";HOSTNAME="+hostname+";PORT=50000;PROTOCOL=TCPIP;UID="+uid+";PWD="+pwd+";"
dsn_ibm_dbi =  "DRIVER = {IBM DB2 ODBC DRIVER}; DATABASE="+ database + ";HOSTNAME="+hostname+";PORT=50000;PROTOCOL=TCPIP;UID="+uid+";PWD="+pwd+";"

# 连接数据库
conn_ibm_dbi = ibm_db_dbi.connect(dsn_ibm_dbi, "", "")
if conn_ibm_dbi:
    print "auth11 is connected"

sql = "select TAGNAME, SOURCE, DESCRIPTION from T_BM_TAG_INDEX;"
c = conn_ibm_dbi.cursor()
c.execute(sql)
data = {}
rows = c.fetchall()

print rows
